﻿// Author: Iulian Lita
// Project: UIModule
// Path: C:\Users\Tym\Documents\Visual Studio 2008\Projects\Library\UIModule
// Creation date: 1/13/2009 2:42 PM
// Last modified: 1/14/2009 4:55 AM

#region Using directives
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using UsersModule.AdminActions;
#endregion

namespace ProjectIp
{
    /// <summary>
    /// Administrator form
    /// </summary>
    public partial class AdministratorForm : Form
    {
        private DefaultAdminActions _adminActions;


        private Form _parentForm;
        /// <summary>
        /// Parent form
        /// </summary>
        public Form ParentForm
        {
            get { return _parentForm; }
            set { _parentForm = value; }
        } // ParentForm

        /// <summary>
        /// Create administrator form
        /// </summary>
        /// <param name="adminActions">Admin actions</param>
        public AdministratorForm(DefaultAdminActions adminActions)
        {
            _adminActions = adminActions;
            InitializeComponent();
        } // AdministratorForm(adminActions)



        private void AdministratorForm_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'allFieldsLibrary.detaliiProdus' table. You can move, or remove it, as needed.
            this.detaliiProdusTableAdapter.Fill(this.allFieldsLibrary.detaliiProdus);
            // TODO: This line of code loads data into the 'libraryDataSet.utilizator' table. You can move, or remove it, as needed.
            this.utilizatorTableAdapter.Fill(this.libraryDataSet.utilizator);



        } // AdministratorForm_Load(sender, e)

        private void users_lview_ColumnClick(object sender, ColumnClickEventArgs e)
        {


        } // users_lview_ColumnClick(sender, e)

        private void logout_btn_Click(object sender, EventArgs e)
        {
            _parentForm.Show();
            this.Dispose();
        } // logout_btn_Click(sender, e)

        private void exit_btn_Click(object sender, EventArgs e)
        {
            Application.Exit();
        } // exit_btn_Click(sender, e)

    

    

        private void utilizatorBindingSource_CurrentChanged(object sender, EventArgs e)
        {

        } // utilizatorBindingSource_CurrentChanged(sender, e)

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        } // dataGridView1_CellContentClick(sender, e)


        private void remove_btn_Click(object sender, EventArgs e)
        {
            try
            {
                int changeValueOf = (int)dgw_Users.SelectedRows[0].Cells[0].Value;
                utilizatorTableAdapter.DropUsers(libraryDataSet.utilizator, changeValueOf);
                utilizatorTableAdapter.Fill(libraryDataSet.utilizator);
                MessageBox.Show("The selected user has been turned non-active");
            }
            catch (Exception)
            {
                Error.ErrorManagement.ManageException(new Exception("No rows were selected on delete call"));
                MessageBox.Show("Please select a row first");
            }
        } // remove_btn_Click(sender, e)


      
        private void penalize_btn_Click(object sender, EventArgs e)
        {
            try
            {
                int selectedUser = (int)dgw_Users.SelectedRows[0].Cells[0].Value;
                string name = (string)dgw_Users.SelectedRows[0].Cells[1].Value;
                if (((byte)dgw_Users.SelectedRows[0].Cells[4].Value )== 0)
                {                    
                    _adminActions.PenalizeUser(selectedUser);
                   
                    utilizatorTableAdapter.Fill(libraryDataSet.utilizator);
                    MessageBox.Show(name + " has been penalized");
                }
                else
                {
                    MessageBox.Show(name + " has a penalty pending!");
                }
            } // try
            catch (Exception)
            {
                Error.ErrorManagement.ManageException(new Exception("No rows were selected on penalize attempt"));
                MessageBox.Show("Please select a row first");
            }
        } // penalize_btn_Click(sender, e)

        private void pay_btn_Click(object sender, EventArgs e)
        {
            try
            {
                int selectedUser = (int)dgw_Users.SelectedRows[0].Cells[0].Value;
                string name = (string)dgw_Users.SelectedRows[0].Cells[1].Value;
                if (((byte)dgw_Users.SelectedRows[0].Cells[4].Value) == 1)
                {
                    _adminActions.Pay(selectedUser);
                    utilizatorTableAdapter.Fill(libraryDataSet.utilizator);
                    MessageBox.Show(name + " has paied the penalty!");
                }
                else
                    MessageBox.Show(name + " has no penalties!");
            } // try
            catch (Exception)
            {
                Error.ErrorManagement.ManageException(new Exception("No rows were selected on pay up attempt"));
                MessageBox.Show("Please select a row first");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {

        } // pay_btn_Click(sender, e)


    } // class AdministratorForm
} // namespace ProjectIp
